package com.hwadee.ems.domain.vo;

import java.time.LocalDate;

import lombok.Data;
import lombok.NoArgsConstructor;

import com.fasterxml.jackson.annotation.JsonIgnore;

import com.hwadee.ems.enums.ApprovalStatus;
import com.hwadee.ems.enums.AssessmentMethod;
import com.hwadee.ems.service.IUserService;
import com.hwadee.ems.service.ICourseService;
import com.hwadee.ems.service.IScheduledCourseService;
import com.hwadee.ems.service.IApprovalService;
import com.hwadee.ems.service.IClassService;
import com.hwadee.ems.service.impl.UserServiceImpl;
import com.hwadee.ems.service.impl.CourseServiceImpl;
import com.hwadee.ems.service.impl.ScheduledCourseServiceImpl;
import com.hwadee.ems.service.impl.ApprovalServiceImpl;
import com.hwadee.ems.service.impl.ClassServiceImpl;
import com.hwadee.ems.domain.po.Approval;
import com.hwadee.ems.domain.po.AssessmentApplication;
import com.hwadee.ems.domain.po.Class;
import com.hwadee.ems.domain.po.Course;
import com.hwadee.ems.domain.po.ScheduledCourse;
import com.hwadee.ems.domain.po.User;

@Data
@NoArgsConstructor
public class AssessmentApplicationVO {

    @JsonIgnore
    private IScheduledCourseService scheduledCourseService = ScheduledCourseServiceImpl.getInstance();

    @JsonIgnore
    private ICourseService courseService = CourseServiceImpl.getInstance();

    @JsonIgnore
    private IClassService classService = ClassServiceImpl.getInstance();

    @JsonIgnore
    private IUserService userService = UserServiceImpl.getInstance();

    @JsonIgnore
    private IApprovalService approvalService = ApprovalServiceImpl.getInstance();


    public AssessmentApplicationVO(AssessmentApplication assessmentApplication) {
        this.id = assessmentApplication.getId();
        this.courseId = assessmentApplication.getCourseId();
        ScheduledCourse scheduledCourse = scheduledCourseService.getById(assessmentApplication.getCourseId());
        Course course = courseService.getById(this.courseId);
        this.courseName = course.getName();
        Class classEntity = classService.getById(scheduledCourse.getClassId());
        this.classId = classEntity.getId();
        this.className = classEntity.getName();
        this.applicantId = assessmentApplication.getApplicantId();
        this.applicantName = userService.getById(assessmentApplication.getApplicantId()).getName();
        this.approvalId = assessmentApplication.getApprovalId();
        Approval approval = approvalService.getById(this.approvalId);
        this.approverId = approval.getApproverId();
        this.approverName = userService.getOptById(this.approverId).map(User::getName).orElse(null);
        this.approvalStatus = approval.getStatus();
        this.approvalOpinion = approval.getOpinion();
        this.approvalDate = approval.getApprovalDate();
        this.reason = assessmentApplication.getReason();
        this.assessmentMethod = assessmentApplication.getAssessmentMethod();
        this.applicationDate = assessmentApplication.getApplicationDate();  
    }

    /**
     * 考核方式申请编号
     */
    private Long id;

    /**
     * 课程编号 references scheduled_course(id) for (name)
     */
    private Long courseId;

    /**
     * 课程名称
     */
    private String courseName;

    /**
     * 上课班级编号 references class(id) for (name)
     */
    private Long classId;

    /**
     * 上课班级名称
     */
    private String className;

    /**
     * 申请人编号 references user(id) for (name)
     */
    private Long applicantId;

    /**
     * 申请人姓名
     */
    private String applicantName;

    /**
     * 审批编号 references approval(id) for (status, opinion, approval_date)
     */
    private Long approvalId;

    /**
     * 审批人编号 references user(id) for (name)
     */
    private Long approverId;

    /**
     * 审批人姓名
     */
    private String approverName;

    /**
     * 审批状态
     */
    private ApprovalStatus approvalStatus;

    /**
     * 审批意见
     */
    private String approvalOpinion;

    /**
     * 审批日期
     */
    private LocalDate approvalDate;

    /**
     * 申请原因
     */
    private String reason;

    /**
     * 考核方式，0代表考试，1代表考查，2代表其他
     */
    private AssessmentMethod assessmentMethod;

    /**
     * 填报日期
     */
    private LocalDate applicationDate;

}
